package com.stedu.config;

import com.stedu.interceptor.JwtInterceptor;
import com.stedu.interceptor.JwtInterceptorOperate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MainConfig implements WebMvcConfigurer {
    @Autowired
    private JwtInterceptor jwtInterceptor;
    @Autowired
    private JwtInterceptorOperate jwtInterceptorOperate;
    @Value("${stedu.picdir}")
    private String picdir;
    @Override
    //配置拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/admin/**")//拦截的地址
                .excludePathPatterns("/user/**");//不拦截的地址
        registry.addInterceptor(jwtInterceptorOperate)
                .addPathPatterns("/user/**")//拦截的地址
                .excludePathPatterns("/admin/**");//不拦截的地址
    }

    @Override
    //本地资源映射，通过浏览器访问服务器资源
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:"+picdir);
    }
}
